#pragma once

#include <string>
#include <unordered_map>

#include <glm/glm.hpp>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <matrix.h>

struct ShaderProgramSource {
    std::string vertexSource;
    std::string fragmentSource;
};

class Shader {
public:
    Shader(const std::string& filepath);
    ~Shader();

    void Bind() const;
    void Unbind() const;

    void SetUniform1i(const std::string& name, int32_t v);
    void SetUniform1f(const std::string& name, float v);
    void SetUniform4f(const std::string& name, float v0, float v1, float v2, float v3);
    void SetUniformMat4f(const std::string& name, const glm::mat4& matrix);
    void SetUniformMat4f(const std::string& name, const Matrix<GLfloat>& matrix);

private:
    int32_t GetUniformLocation(const std::string& name);
    struct ShaderProgramSource ParseShader(const std::string& filepath);
    uint32_t CompileShader(uint32_t type, const std::string& source);
    uint32_t CreateShader(const std::string& vertexShader, const std::string& fragmentShader);

    uint32_t rendererID_ = 0;
    std::string filepath_;
    std::unordered_map<std::string, int32_t> uniformLocationCache_;
};
